function All() {}
All.prototype = {
    timer: "",
    debounce(fn, delay = 500) {
        var _this = this;
        return function(arg) {
            //获取函数的作用域和变量
            let that = this;
            let args = arg;
            clearTimeout(_this.timer) // 清除定时器
            _this.timer = setTimeout(function() {
                fn.call(that, args)
            }, delay)
        }
    },
    setCookie(val) { //cookie设置[{key:value}]、获取key、清除['key1','key2']
        for (var i = 0, len = val.length; i < len; i++) {
            for (var key in val[i]) {
                document.cookie = key + '=' + encodeURIComponent(val[i][key]) + "; path=/";
            }
        }
    },
    getCookie(name) {
        var strCookie = document.cookie;
        var arrCookie = strCookie.split("; ");
        for (var i = 0, len = arrCookie.length; i < len; i++) {
            var arr = arrCookie[i].split("=");
            if (name == arr[0]) {
                return decodeURIComponent(arr[1]);
            }
        }
    },
    clearCookie(name) {
        var myDate = new Date();
        myDate.setTime(-1000); //设置时间    
        for (var i = 0, len = name.length; i < len; i++) {
            document.cookie = "" + name[i] + "=''; path=/; expires=" + myDate.toGMTString();
        }
    },
    arrToStr(arr) {
        if (arr) {
            return arr.map(item => { return item.name }).toString()
        }
    },
    toggleClass(arr, elem, key = 'id') {
        return arr.some(item => { return item[key] == elem[key] });
    },
    toChecked(arr, elem, key = 'id') {
        var isIncludes = this.toggleClass(arr, elem, key);
        !isIncludes ? arr.push(elem) : this.removeEle(arr, elem, key);
    },
    removeEle(arr, elem, key = 'id') {
        var includesIndex;
        arr.map((item, index) => {
            if (item[key] == elem[key]) {
                includesIndex = index
            }
        });
        arr.splice(includesIndex, 1);
    },
    setApproverStr(nodeConfig) {
        if(nodeConfig.automaticType=='1'){
            if(nodeConfig.members=='1'){
               // console.log(nodeConfig.addMembers);
                let str = ''
                nodeConfig.addMembers.forEach((item)=>{
                    if(str==''){
                        str= str+item.name
                    }else{
                        str= str + ','+item.name
                    }
                })
                return str
            }else if(nodeConfig.members=='2'){
                    // 发起人自选
                    console.log(nodeConfig);
                    if(nodeConfig.scope=='1'){
                        let str = ''
                        nodeConfig.membersRange.forEach((item)=>{
                            if(str==''){
                                str= str+item.name
                            }else{
                                str= str + ','+item.name
                            }
                        })
                        return str
                    }else if(nodeConfig.scope=='2'){
                        let str = ''
                        nodeConfig.membersRange.forEach((item)=>{
                            if(str==''){
                                str= str+item.name
                            }else{
                                str= str + ','+item.name
                            }
                        })
                        return str
                    }
            }else if(nodeConfig.members=='3'){
                if(nodeConfig.examinationend=='1'){
                    let str = ''
                        nodeConfig.continuous.forEach((item)=>{
                            if(str==''){
                                str= str+item.name
                            }else{
                                str= str + ','+item.name
                            }
                        })
                        return str
                }else if(nodeConfig.examinationend=='2'){
                    return "通讯录中的"+nodeConfig.address+'级主管'
                }
            }else if(nodeConfig.members=='4'||nodeConfig.members=='5'){
                return "发起人"+nodeConfig.originatorout+'级主管'
            }else if(nodeConfig.members=='6'){
                return nodeConfig.department+"部门内的主管"+nodeConfig.role
            }else if(nodeConfig.members=='7'){
                let str = ''
                nodeConfig.grtye.forEach((item)=>{
                    if(str==''){
                        str= str+item.name
                    }else{
                        str= str + ','+item.name
                    }
                })
                return str
            }else if(nodeConfig.members=='8'){
                let str = ''
                nodeConfig.addRole.forEach((item)=>{
                    if(str==''){
                        str= str+item.name
                    }else{
                        str= str + ','+item.name
                    }
                })
                return str
            }else if(nodeConfig.members=='9'){
                return '发起人'
            }else if(nodeConfig.members=='0'){
                return '表单字段'+nodeConfig.scontact+"用户"
            }
        }else if(nodeConfig.automaticType=='2'){S
            return '自动通过'
        }else if(nodeConfig.automaticType=='3'){
            return '自动拒绝'
        }
    },
    dealStr(str, obj) {
        let arr = [];
        let list = str.split(",");
        for (var elem in obj) {
            list.map(item => {
                if (item == elem) {
                    arr.push(obj[elem].value)
                }
            })
        }
        return arr.join("或")
    },  
    conditionStr(nodeConfig, index) {
       // console.log(nodeConfig.conditionNodes[index]);
        if(nodeConfig.conditionNodes[index].Datalist && nodeConfig.conditionNodes[index].Datalist.length!=0){
            let str = ''
            nodeConfig.conditionNodes[index].Datalist.forEach(v=>{
                let vtr = ''
                v.screeningList.forEach(k=>{
                    if(k.screeningType==1){
                        let otr = ''
                        k.puslist.forEach(o=>{
                            if(otr==''){
                                otr= otr+o.name
                            }else{
                                otr= otr + ','+o.name
                            }
                        })
                        if(vtr==''){
                            vtr=otr
                        }else{
                            vtr=vtr+' 且 '+otr
                        }
                    }else if(k.screeningType==2){
                        if(vtr==''){
                            vtr=k.title+this.jishun(k.contrast)+k.value
                        }else{
                            vtr=vtr+' 且 '+k.title+this.jishun(k.contrast)+k.value
                        }
                    }else if(k.screeningType==3){
                        if(vtr==''){
                            vtr=k.maintableuk+this.jishun(k.contrast)+k.value
                        }else{
                            vtr=vtr+' 且 '+k.maintableuk+this.jishun(k.contrast)+k.value
                        }
                    }
                })
                if(str==''){
                    str=str+vtr
                }else{
                    str=str+'或'+vtr
                }
            })
          //  console.log(str,"qqqQQQQQQQQQ");
            return str
        }else{
            return "请设置条件"
        }
    },
    jishun(contrast){
        switch(contrast){
            case "1" :
                return '大于'
            case "2" :
                return '小于'
            case "3" :
                return '大于等于'
            case "4" :
                return '大于等于'
            case "5" :
                return '等于'
                                                    
        }
    },
    copyerStr(nodeConfig) {
        if (nodeConfig.configuration== 1&&nodeConfig.tags) {
            return this.arrToStr2(nodeConfig.tags)
        } else if (nodeConfig.configuration== 2) {
            // console.log(nodeConfig.tagsid);
            return nodeConfig.tagsid.label
        }else if (nodeConfig.configuration== 3){
            return '负责人'
        }else if (nodeConfig.configuration== 4) {
            return '主管理员'
        } else{
            return ''
        }
    }, 
    arrToStr2(tags){
        // console.log(tags);
        let obj = ''
        if(tags){
             tags.forEach(element => {
            obj=element.name+','+obj
        });
        return obj.slice(0,obj.length-1)
        }
    },
    toggleStrClass(item, key) {
        let a = item.zdy1 ? item.zdy1.split(",") : []
        return a.some(item => { return item == key });
    },
}

export default new All();